"""
@Project:p8_syl_flask
@File:vip.py
@Author:郑凯乐
@Date:18:33
"""
import json
from flask import Blueprint,jsonify
from flask_restful import Api,Resource,marshal
from common.models.user import Vip
from common.model_fields.user_fields import vip_fields
vip_bp = Blueprint('vip',__name__, url_prefix='/vip')
api = Api(vip_bp)

class VIPinfoResource(Resource):
    def get(self):
        """获取vip信息"""
        vips = Vip.query.all()
        result = {}
        for vip in vips:
            if vip.level == 0:
                #是普通用户
                vsp = marshal(vip,vip_fields)
                common_list = json.loads(json.dumps(vsp))
                result['common_list'] = common_list
            if vip.level == 1:
                #是普通会员
                common_vip_list = json.loads(json.dumps(marshal(vip,vip_fields)))
                common_vip_list['level'] = "普通会员"
                result["common_vip_list"] = common_vip_list
            if vip.level == 2:
                # 是高级会员
                expert_vip_list = json.loads(json.dumps(marshal(vip, vip_fields)))
                expert_vip_list['level'] = '高级会员'
                result['expert_vip_list'] = expert_vip_list
            # return jsonify(message="ok",data=result,code=200)
        return jsonify(message='ok', data=result, code=200)

api.add_resource(VIPinfoResource,'/get_vip_list')
